package com.haitaoit.chengquan.module.center.adapter.order;

import android.content.Context;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.RelativeSizeSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.haitaoit.chengquan.R;
import com.haitaoit.chengquan.base.BackCall;
import com.haitaoit.chengquan.module.center.model.MyOrderModel2;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;

import java.util.List;

/**
 * Created by Administrator on 2016/10/13.
 */
public class MyOrderItemAdapter extends BaseAdapter {
    private Context context;
    private BackCall backCall;
    private List<MyOrderModel2> list;

    public void setBackCall(BackCall backCall) {
        this.backCall = backCall;
    }

    public MyOrderItemAdapter(Context context) {
        this.context = context;
    }

    public List<MyOrderModel2> getList() {
        return list;
    }

    public void setList(List<MyOrderModel2> list) {
        this.list = list;
    }

    @Override
    public int getCount() {
        return list == null ? 0 : list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, final ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.my_yuyue_item2, null);
            holder = new ViewHolder();
            ViewUtils.inject(holder, convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        // 部分字体变大变色
        SpannableString msp = new SpannableString("¥ " + list.get(position).getPrice());
        msp.setSpan(new RelativeSizeSpan(1.5f), 1, ("¥ " + list.get(position).getPrice()).length(),
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        holder.yuyue_money.setText(msp);

//        ImageLoader.getInstance().displayImage(list.get(position).getImg_url(), holder.order_img);
        Glide.with(context).load(list.get(position).getImg_url()).into(holder.order_img);
        holder.order_title.setText(list.get(position).getTitle());
        holder.yuyue_content.setText("规格：" + list.get(position).getSpecifications());

        //先把显示的数量给隐藏了
        holder.goods_num.setText("X " + list.get(position).getCount());
        holder.goods_num.setVisibility(View.GONE);
        return convertView;
    }

    class ViewHolder {
        @ViewInject(R.id.order_img)
        ImageView order_img;
        @ViewInject(R.id.order_title)
        TextView order_title;
        @ViewInject(R.id.yuyue_content)
        TextView yuyue_content;
        @ViewInject(R.id.yuyue_money)
        TextView yuyue_money;
        @ViewInject(R.id.goods_num)
        TextView goods_num;
    }
}
